//
//  BGShopAddListViewController.m
//  bigMall
//
//  Created by LTOVE on 16/8/9.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGShopAddListViewController.h"
#import "BGShopAddListBasicModel.h"

#import "BGShopAddListCell.h"
#import "LTOVEDynamicCreakButton.h"

#import "BGAddlistWithaccessoryViewModel.h"
#import "BGDateResult.h"

#import "BGAttrChangePricePrame.h"

#import "MJExtension.h"

#import "BGAttrChangePriceResultModel.h"

#import "UIImage+LTOVEImageWithColor.h"
#import "BGId_ValueModel.h"
#import "BGWebViewController.h"

#import "BGAddListTextFildViewModel.h"
//#import "BGShopAddListBasicModel.h"
#import "BGAddListParamModel.h"
#import "BGCreateOrderModel.h"
#import "BGLoginViewController.h"

#import "BGShopAddListBasicModel.h"
#import "BGAddListTitleModel.h"

#import <UITableView_FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h>
@interface BGShopAddListViewController (){
    
//    NSArray *_dataArray;
    LTOVEDynamicCreakButton *_btnView;
    NSIndexPath *_indexPath;
//    BGAttrChangePricePrame *_parames;
    NSString *_textFildText;
    NSString *_status;//计算价格的状态
    NSString *_dateTimeValue;
    UIButton *_selectBtn;
    UITapGestureRecognizer *_tap;
//    NSUInteger count;
    
    BGAddListParamModel *ParamModel;
    NSMutableArray *_doubleChooseArray;
}
@property (nonatomic,strong)BGAttrChangePricePrame *parames;
@property (nonatomic,strong)NSMutableArray *paramDicArray;
/**
 *  数据源数组
 */
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSArray *arrays;

@end
@interface BGShopAddListViewController ()<dynamicButtonDelegate,BGShopAddListCellDelegate>

@end

@implementation BGShopAddListViewController

- (NSMutableArray *)paramDicArray
{
    if (!_paramDicArray) {
        _paramDicArray = [NSMutableArray array];
    }
    return _paramDicArray;
}
/**
    解析传回来的数据
 */
- (NSMutableArray *)getDataArrayWithSourceArray:(NSArray *)array
{
    _status = @"1";
    NSMutableArray *MutableArray = [[NSMutableArray alloc]initWithArray:array];
//    count = array.count;
    if (!_doubleChooseArray) {
        _doubleChooseArray = [NSMutableArray array];
    }
    self.arrays = array;
    for (int i = 0; i < MutableArray.count; i++) {
        BGShopAddListBasicModel *model = MutableArray[i];
        if ([model.attr_type isEqualToString:@"4"]){
            BGShopAddListBasicModelType4 *itemModel = (BGShopAddListBasicModelType4 *)model;
            NSMutableArray *valueArray = [NSMutableArray array];
            for (int i = 0; i < model.is_default.count; i++) {
                NSObject *str = model.is_default[i];
//                NSLog(@"%lu",(unsigned long)str.length);
                if ([str isKindOfClass:[NSString class]]) {
                    if ([model.is_default[i] isEqualToString:@"true"]) {
                        NSString *str = itemModel.dataArray[i];
                        str = [[str componentsSeparatedByString:@"浮"] firstObject];
                        NSDictionary *dic = @{
                                              @"id":itemModel.idStr,
                                              @"value":str
                                              };
                        [valueArray addObject:dic];
                    }
                }else{
                    NSMutableArray *vaArray = [NSMutableArray array];
                    for (int i = 0 ; i < model.is_default.count; i++) {
                        [vaArray addObject:@"false"];
                    }
                    model.is_default = vaArray;
                }
            }
            NSDictionary *dic = @{
                                  @"name":itemModel.idStr,
                                  @"value":valueArray
                                  };
            [_doubleChooseArray addObject:dic];
        }
        if ([model.attr_type isEqualToString:@"3"] || [model.attr_type isEqualToString:@"5"]) {
            BGAddlistWithaccessoryViewModel *models = (BGAddlistWithaccessoryViewModel *)model;
            NSArray *array = models.dataArray[0];
            
            if (array.count < 2) {
                if (!_paramDicArray) {
                    _paramDicArray = [NSMutableArray array];
                }
//                NSArray *aa = models.dataArray[0];
                NSString *str = [array firstObject];
                [_paramDicArray addObject:[self valueAddToDic:models.idStr Value:str]];
                //                [MutableArray removeObject:models];
                [MutableArray removeObjectAtIndex:i];
                i--;
            }else{
                [_paramDicArray addObject:[self valueAddToDic:models.idStr Value:[NSString stringWithFormat:@"%@ ",models.defaultStr]]];
            }
        }
        
    }
    
    return MutableArray;
}
#pragma mark -初始化控制器
+ (BGShopAddListViewController *)initAddListviewWithDataArray:(NSArray *)dataArray
{
    BGShopAddListViewController *viewC = [[BGShopAddListViewController alloc]init];
#warning 这里需要解析数据
    [viewC.tableView registerClass:[BGShopAddListCell class] forCellReuseIdentifier:@"cell"];
//    viewC.dataArray = [[NSMutableArray alloc]initWithArray:dataArray];;
    viewC.dataArray = [viewC getDataArrayWithSourceArray:dataArray];
    /**
     *  初始化获取价格参数
     */
    BGAttrChangePricePrame *param = [BGAttrChangePricePrame parameWithtype:@"Coal" goodsId:viewC.goodId buyNumber:nil objType:@"goods" attrArray:nil];
    //    NSString *gss = self.goodId;
    viewC.parames = param;
    [viewC.tableView reloadData];
    return viewC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@"%@",_dataArray);
    [self.tableView reloadData];
//    self.tableView.style = UITableViewStylePlain;
//    [self initWithStyle:UITableViewStyleGrouped];
    _dateTimeValue = @"";
//    [self.tableView registerClass:[BGShopAddListCell class] forCellReuseIdentifier:@"cell"];
//    [self.tableView regis]
    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    
    self.tableView.separatorInset = UIEdgeInsetsZero;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    //监听键盘消失
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDissmissNoti) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShowNoti) name:UIKeyboardWillShowNotification object:nil];
  
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    
    ParamModel = [BGAddListParamModel new];
    ParamModel.type = @"mall";
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, BGButtonCellHeigh, 0);
    
}

- (void)keyBoardShowNoti
{
    _tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeKeyBoard)];
    [self.tableView addGestureRecognizer:_tap];
}

/**
 *  键盘消失
 */
- (void)keyBoardDissmissNoti
{
    GWLog(@"键盘消失了");
//    CGFloat Num = [self.Num floatValue];
//    CGFloat leastNum = [self.leastNum floatValue];
//    CGFloat valu = [_textFildText floatValue];
//    if (valu < leastNum || valu > Num) {
//        //弹窗
//        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:@"采购量不能低于最低采购量且不能高于库存剩余量" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//            
//           _textFildText = @"";
//            
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"textFildChange" object:nil];
//            
//        }];
//        [alertVc addAction:cancel];
//        [self presentViewController:alertVc animated:YES completion:^{
//            
//            
//        }];
//        
//    }
    [self.tableView removeGestureRecognizer:_tap];
    if (_textFildText.length != 0) {
        _parames.buyNumber = _textFildText;
        [self isParamDicArrayIsEndToAddValue];
    }
    
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)closeKeyBoard
{
    [self.tableView endEditing:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    //添加底部立即下班button
    NSDictionary *dic = @{
                          NSFontAttributeName:Font34,
                          NSForegroundColorAttributeName:lightwhite_
                          };
    CGFloat x = BGButtonCellHeigh;
    CGFloat heigh = screenH - x;
    //    NSLog(@"%f--%f--%f",screenH,heigh,BGButtonCellHeigh);
    LTOVEDynamicCreakButton *btnView = [LTOVEDynamicCreakButton buttonViewWithFrame:CGRectMake(0,heigh, screenW, BGButtonCellHeigh) titleDataArray:@[@"立即下单"] andEdgInset:UIEdgeInsetsMake(10, BGMaginLeft, 10, BGMaginLeft) andMaginX:0 andMaginY:0 andBtnHeigh:BGMessageBtn andBtnNorColor:read_ andBtnHeighColor:read_ andRadius:7 andFont:dic];
    //    btnView.y = 100;
    btnView.delegate = self;
    //    self.tableView.tableFooterView = btnView;
    //    self.tableView.
    _btnView = btnView;
//    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, BGButtonCellHeigh, 0);
    [BGKeyWindow addSubview:btnView];
}

- (void)viewWillDisappear:(BOOL)animated
{
     [_btnView removeFromSuperview];
//    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
#pragma  mark 下单按钮点击
/**
 *  立即下单button点击
 *
 *  @param btn btn description
 */
- (void)dynamicButtonClick:(UIButton *)btn
{
//    NSLog(@"点击了立即下单按钮");
////    NSString *ststs = _status;
//    NSLog(@"%@",_dateTimeValue);
//    NSLog(@"%@",_status);
#warning 显示提货时间是需注掉下边一行
    _dateTimeValue = @"a";
    if (_dateTimeValue.length  && [_status isEqualToString:@"1"]) {
//       NSLog(@"-------->点击了立即下单按钮");
        GWLog(@"%@",ParamModel.keyValues);
        
        [BGDateResult createOrderWithParamDic:ParamModel.keyValues success:^(NSObject *result) {
            BGCreateOrderModel *models = (BGCreateOrderModel *)result;
            GWLog(@"%@",models.msg);
            
            UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:models.msg preferredStyle:UIAlertControllerStyleAlert];
            NSString *btnStr;
            if ([models.status isEqualToString:@"-2"]) {
                btnStr = @"去登录";
            }else{
                btnStr = @"好";
            }
            UIAlertAction *sure = [UIAlertAction actionWithTitle:btnStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                if ([models.status isEqualToString:@"-2"]) {
                    BGLoginViewController *vc = [BGLoginViewController new];
                    [self.navigationController pushViewController:vc animated:YES];
                }else{
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
            }];
            
            [alertVc addAction:sure];
            [self presentViewController:alertVc animated:YES completion:^{
                
                
            }];
        } failure:^(NSError *error) {
            
            
        }];
        
//         [self.navigationController popToRootViewControllerAnimated:YES];
    }else if(_selectBtn.selected){
        
        [self alertMessageWith:@"必须同意采购协议"];

    }else
        [self alertMessageWith:@"请选择提货时间"];
   
    
}

- (void)alertMessageWith:(NSString *)msg
{
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    [alertVc addAction:cancel];
    [self presentViewController:alertVc animated:YES completion:^{
        
        
    }];
}
- (void)hetongBtnClick:(UIButton *)btn
{
#warning 跳转阅读合同
    BGWebViewController *webViewC = [BGWebViewController webViewWithUrlStr:@"http://hm.thinklev.com/protocol_protocol_mall.html"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]init];
    item.title = @"";
    self.navigationItem.backBarButtonItem = item;
    webViewC.title = @"采购销售协议合同";
    [self.navigationController pushViewController:webViewC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
/**
 *  分割线顶格
 */
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
//    NSLog(@"%lu",(unsigned long)_dataArray.count);
    return _dataArray.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BGShopAddListBasicModel *model = _dataArray[indexPath.row];
    
    if ([model isKindOfClass:[BGShopAddListBasicModelType4 class]]) {
        return [tableView fd_heightForCellWithIdentifier:@"cell" configuration:^(BGShopAddListCell* cell) {
            
            cell.model = model;
        }];
    }else{
        return 43.5;
    }
//    return 250;
}


- (UIView *)addHetongView
{
    UIView *footView = [[UIView alloc]init];
    footView.size = CGSizeMake(screenH, 44);
    footView.backgroundColor = [UIColor whiteColor];
    //按钮
    UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selectBtn.frame = CGRectMake(BGMaginLeft, 0, 15, 15);
    selectBtn.centerY = 22;
    [selectBtn setBackgroundImage:[UIImage imageWithColor:[UIColor redColor] size:selectBtn.size] forState:UIControlStateNormal];
    [selectBtn setBackgroundImage:[UIImage imageWithColor:[UIColor greenColor] size:selectBtn.size] forState:UIControlStateSelected];
    [selectBtn addTarget:self action:@selector(btnClickWith:) forControlEvents:UIControlEventTouchUpInside];
//        selectBtn.selected = YES;
    _selectBtn = selectBtn;
    [footView addSubview:selectBtn];
    //文字
    UILabel *textLabel = [[UILabel alloc]init];
    textLabel.text = @"已阅读并同意";
    textLabel.font = Font30;
    textLabel.textColor = textGrayColor;
    [textLabel sizeToFit];
    textLabel.x = CGRectGetMaxX(selectBtn.frame) + 5;
    textLabel.centerY = selectBtn.centerY;
    [footView addSubview:textLabel];
    //合同按钮
    UIButton *hetongBTN = [UIButton buttonWithType:UIButtonTypeCustom];
    [hetongBTN setTitle:@"《采购销售协议合同》" forState:UIControlStateNormal];
    [hetongBTN setTitleColor:read_ forState:UIControlStateNormal];
    hetongBTN.titleLabel.font = Font30;
    hetongBTN.selected = YES;
    [hetongBTN sizeToFit];
    [hetongBTN addTarget:self action:@selector(hetongBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:hetongBTN];
    footView.hidden = YES;
    hetongBTN.x = CGRectGetMaxX(textLabel.frame) + 5;
    hetongBTN.centerY = textLabel.centerY;
    return footView;
}



- (void)btnClickWith:(UIButton *)btn
{
    btn.selected = !btn.selected;
}


//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 88;
//}
#pragma mark - cellForRow
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row >= _dataArray.count) {
        UIView *view = [self addHetongView];
            UITableViewCell * cell = [UITableViewCell new];
            cell.selected = NO;
    //        cell.userInteractionEnabled = NO;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
//        cell.userInteractionEnabled = NO;
            [cell.contentView addSubview:view];
            return cell;
        
    }
    
    BGShopAddListCell *cell = [BGShopAddListCell cellWithTableView:tableView IndexPath:indexPath];
    BGShopAddListBasicModel *model = _dataArray[indexPath.row];
    model.indexPath = indexPath;
    // Configure the cell...
    cell.delegate = self;
    cell.model = model;
    return cell;
}

#pragma mark -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row >= _dataArray.count) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    _indexPath = indexPath;
    BGShopAddListBasicModel *model = _dataArray[indexPath.row];
    if (model.option) {
        model.option();
        return;
        
    }
    
    
}

#pragma cell值改变的代理方法

- (void)cellValueChangedWithModel:(BGShopAddListBasicModel *)model
{
    if ([model isKindOfClass:[BGAddListTextFildViewModel class]]) {
        BGAddListTextFildViewModel *itemModel = (BGAddListTextFildViewModel *)model;
        GWLog(@"+++++++++++++++>>>>>%@",itemModel.indexPath);
        [_dataArray replaceObjectAtIndex:itemModel.indexPath.row withObject:itemModel];
        
    }else if ([model isKindOfClass:[BGAddlistWithaccessoryViewModel class]]){
    
        
    }
}


- (void)cellValueChanged:(NSString *)value istextFild:(BOOL)isTextFild
{
//    NSString *strs = _dataArray[_indexPath.row];
    if (isTextFild) {
        

        _textFildText = value;
        
        GWLog(@"+++++++++++++++%@",value);
        
    }else{
        GWLog(@"-------------%@",value);
        [self pickViewVauleChange:value];

    }
}
#pragma mark 加载计算价格

- (NSArray *)getAttrArrayWithSourceArray:(NSArray *)sourceArray
{
    NSMutableArray *array = [NSMutableArray array];
    NSLog(@"%@",_paramDicArray);
    [array addObjectsFromArray:_paramDicArray];
    for (NSDictionary *dic in _doubleChooseArray) {
        NSArray *dicArray= dic[@"value"];
        if (dicArray.count > 0) {
            [array addObjectsFromArray:dicArray];
        }
    }
    return array;
}

/**
 *  加载价格数据
 */
- (void)loadPriceData
{
    _parames.goodsId = self.goodId;
    _parames.attr = [self getAttrArrayWithSourceArray:_parames.attr];
    [BGDateResult attrChangePricewithPrameDic:_parames.keyValues success:^(NSObject *result) {
        BGAttrChangePriceResultModel *model = (BGAttrChangePriceResultModel *)result;
//        NSLog(@"%@,%@",model.msg,model.unitPrice);
        
        if ([model.status isEqualToString:@"1"]) {
            _status = model.status;
            ParamModel.goodsId = _parames.goodsId;
            ParamModel.price = model.unitPrice;
            ParamModel.totalPrice = model.totalPrice;
            ParamModel.number = _parames.buyNumber;
            ParamModel.attr = _parames.attr;
//            NSDictionary *dic = model.res;
            NSString *price = [NSString stringWithFormat:@"%@ 元",model.unitPrice];
            NSString *totPrice = [NSString stringWithFormat:@"%@ 元",model.totalPrice];
            NSArray *stringArry = @[price,totPrice];
            NSMutableArray *array = [NSMutableArray array];
            for (NSUInteger i = _dataArray.count - 2; i < _dataArray.count; i ++) {
                
                
                NSIndexPath *indexP = [NSIndexPath indexPathForRow:i inSection:0];
                [array addObject:indexP];
            }
            
            [self reloadTableViewCellsWithAppendStr:stringArry andIndexArray:array];
            
        }
        
        NSLog(@"%@",self.goodId);
    } failure:^(NSError *error) {
        
        
    }];
}

/**
 *  把值加入字典
 *
 *  @param name  name description
 *  @param value value description
 *
 *  @return return value description
 */
- (NSDictionary *)valueAddToDic:(NSString *)name Value:(NSString *)value
{
    NSArray *array = [value componentsSeparatedByString:@" "];
    NSDictionary *dic = @{
                            @"id":name,
                            @"value":[array firstObject],
                          };
    return dic;
}

#pragma mark -
#pragma mark - 多选值改变

- (void)cellValueWithDoubleValueChangedWithArray:(NSArray *)array adnIndexPath:(NSString *)idStr
{
    NSLog(@"%@-=-=-=-=-=-=-",idStr);
    for (int i = 0 ; i < _doubleChooseArray.count; i++) {
        NSDictionary *dic = _doubleChooseArray[i];
        if ([dic[@"name"] isEqualToString:idStr]) {
//            dic[@"value"] = array;
            NSDictionary *newDic = @{
                                        @"name":idStr,
                                        @"value":array
                                     };
            [_doubleChooseArray replaceObjectAtIndex:i withObject:newDic];
            break;
        }
    }
    NSLog(@"%@---",_doubleChooseArray);
    [self loadPriceData];
}

- (void)pickViewVauleChange:(NSString *)string
{
    BGAddlistWithaccessoryViewModel *model = _dataArray[_indexPath.row];
    
//    NSString *titStr = model.title;
    
    if (model.idStr) {
      //商品属性改变
//        NSDictionary *dics = [self valueAddToDic:model.idStr Value:string];
        if (!_paramDicArray) {
            _paramDicArray = [NSMutableArray array];
        }
        BOOL isRep = NO;
        for (int i = 0; i < _paramDicArray.count; i++) {
            NSDictionary *dic = _paramDicArray[i];
            if ([dic[@"id"] isEqualToString:model.idStr]) {
                [_paramDicArray replaceObjectAtIndex:i withObject:[self valueAddToDic:model.idStr Value:string]];
                isRep = YES;
            }
        }
        if (!isRep) {
            [_paramDicArray addObject:[self valueAddToDic:model.idStr Value:string]];
        }
        

        [self isParamDicArrayIsEndToAddValue];
    }else{
        _dateTimeValue = string;
    }

    [self reloadTableViewCellsWithAppendStr:@[string] andIndexArray:@[_indexPath]];
    

}
/**
 *  刷新cell数据
 *
 *  @param string     string description
 *  @param indexArray indexArray description
 */
- (void)reloadTableViewCellsWithAppendStr:(NSArray *)stringArray andIndexArray:(NSArray *)indexArray
{
    for (int i = 0 ; i < indexArray.count; i++) {
        NSIndexPath *indexPa = indexArray[i];
        NSString *string = stringArray[i];
        BGAddlistWithaccessoryViewModel *model = _dataArray[indexPa.row];
        NSString *titStr = model.title;
        NSRange rang = [model.title rangeOfString:@":"];
        if (rang.location !=NSNotFound) {
            titStr = [model.title substringWithRange:NSMakeRange(0, rang.location + 1)];
        }
        
        NSMutableString *titleStr = [[NSMutableString alloc]initWithFormat:@"%@  ",titStr];
        [titleStr appendString:string];
        model.title = titleStr;
//        [_dataArray replaceObjectAtIndex:_indexPath.row withObject:model];
    }
    
    
    
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
}

/**
 *  判断是否选择完整
 *
 *  @return return value description
 */
- (BOOL)isParamDicArrayIsEndToAddValue
{
    [self loadPriceData];
    _status = @"1";
    return YES;
}
//- (BOOL)isParamDicArrayIsEndToAddValue
//{
//    int j = 0;
//    for (int i = 0; i < self.arrays.count; i ++) {
//        
//        BGAddlistWithaccessoryViewModel *model = self.arrays[i];
//        NSDictionary *dic = model.keyValues;
//        NSArray *allKey = dic.allKeys;
//        for (NSString *str  in allKey) {
////            j = [str isEqualToString:@"idStr"] ? j++:j;
//            if ([str isEqualToString:@"idStr"]) {
//                j++;
//            }
//        }
//
//    }
//    if (_paramDicArray.count >= j&& _textFildText.length) {
//        
//        _parames.attr = _paramDicArray;
//        NSLog(@"%@",_paramDicArray);
//        [self loadPriceData];
//        return YES;
//    }else
//        return NO;
//    
//}


@end
